package com.pd.backend.service.impl;

import com.pd.backend.entity.PdOrderClassifyAttach;
import com.pd.backend.dao.PdOrderClassifyAttachDao;
import com.pd.backend.service.PdOrderClassifyAttachService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 车次车辆司机订单分类关联表(PdOrderClassifyAttach)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:34
 */
@Service("pdOrderClassifyAttachService")
public class PdOrderClassifyAttachServiceImpl implements PdOrderClassifyAttachService {
    @Resource
    private PdOrderClassifyAttachDao pdOrderClassifyAttachDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdOrderClassifyAttach queryById(String id) {
        return this.pdOrderClassifyAttachDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdOrderClassifyAttach 筛选条件
     * @param pageRequest           分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdOrderClassifyAttach> queryByPage(PdOrderClassifyAttach pdOrderClassifyAttach, PageRequest pageRequest) {
        long total = this.pdOrderClassifyAttachDao.count(pdOrderClassifyAttach);
        return new PageImpl<>(this.pdOrderClassifyAttachDao.queryAllByLimit(pdOrderClassifyAttach, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdOrderClassifyAttach 实例对象
     * @return 实例对象
     */
    @Override
    public PdOrderClassifyAttach insert(PdOrderClassifyAttach pdOrderClassifyAttach) {
        this.pdOrderClassifyAttachDao.insert(pdOrderClassifyAttach);
        return pdOrderClassifyAttach;
    }

    /**
     * 修改数据
     *
     * @param pdOrderClassifyAttach 实例对象
     * @return 实例对象
     */
    @Override
    public PdOrderClassifyAttach update(PdOrderClassifyAttach pdOrderClassifyAttach) {
        this.pdOrderClassifyAttachDao.update(pdOrderClassifyAttach);
        return this.queryById(pdOrderClassifyAttach.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdOrderClassifyAttachDao.deleteById(id) > 0;
    }
}
